package com.maxiaoke.boot.config;

import com.maxiaoke.boot.interceptor.LoginInterceptor;
import com.maxiaoke.boot.interceptor.RedisUrlCountInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AdminWebConfig implements WebMvcConfigurer {


    /**
     * Filter、Inceptor 几乎拥有同样的功能,有什么区别？
     * 1. filter是Servlet定义的原生组件，好处是可以脱离Spring应用
     * 2. Inceptor是Spring定义的接口,可以使用Spring的自动配置等功能，可以直接@Autowired
     */
    @Autowired
    RedisUrlCountInterceptor redisUrlCountInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**") //所有请求都被拦截，包括静态资源
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**");

        registry.addInterceptor(redisUrlCountInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**");

    }
}
